package cn.hubujyjs.mooc.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    public static <T> Result<T> success(){
        Result<T> tResult = new Result<>();
        tResult.code=200;
        tResult.msg="成功";
        tResult.data=null;
        return tResult;
    }
    public static <T> Result<T> success(T data){
        Result<T> tResult = new Result<>();
        tResult.code=200;
        tResult.msg="成功";
        if (data!=null){
            tResult.data=data;
        }
        return tResult;
    }
    public static <T> Result<T> error(){
        Result<T> tResult = new Result<>();
        tResult.code=201;
        tResult.msg="失败";
        tResult.data=null;
        return tResult;
    }
    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }
    public Result<T> message(String msg){
        this.setMsg(msg);
        return this;
    }


}
